package com.example.ajax.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author ddone
 * @date 2024/3/15-11:21
 */
@WebServlet("/axiosServlet")
public class AxiosServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    /**
     *  响应数据的方式
     *      1. 转发: 页面
     *      2. 重定向: 页面
     *      3. 响应字符串数据: resp.getWriter().write(""); 这个是最多的
     *
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("测试方法是否进入");
        req.setCharacterEncoding("utf-8");
        String id = req.getParameter("id");
        String name = req.getParameter("name");
        System.out.println("服务器接收客户端数据:"+id+":::"+name);
        String msg = "业务服务器处理完成,响应客户端!!!";
        resp.setContentType("text/html;charset=utf-8");
        resp.getWriter().write(msg);
    }
}
